Skip to content

[KYUUBI #7635][SPARK] Support Zstd compression for Arrow IPC query results - #7636

Open
byronwang123 wants to merge 8 commits into
apache:masterfrom
byronwang123:kyuubi-7635-arrow-ipc-compression
Open

[KYUUBI #7635][SPARK] Support Zstd compression for Arrow IPC query results#7636
byronwang123 wants to merge 8 commits into
apache:masterfrom
byronwang123:kyuubi-7635-arrow-ipc-compression

Conversation

@byronwang123

@byronwang123 byronwang123 commented Aug 14, 2026

Copy link
Copy Markdown

Why are the changes needed?

Kyuubi's Arrow result format reduces serialization/deserialization overhead, but Arrow IPC results are currently transferred without compression. For large result sets, network transfer can become a significant part of fetch latency.

This follows up on #3877 (related issue #3865). Spark 4.1 introduced the upstream Arrow compression configurations (SPARK-54134), so this PR follows Spark's configuration and Arrow IPC compression semantics instead of introducing a Kyuubi-specific protocol.

The main changes are:

  • Support none (default) and zstd for Arrow IPC query results, including ZSTD compression-level configuration.
  • Preserve compression when Arrow batches are sliced, e.g. when LIMIT crosses a batch boundary.
  • Decode compressed batches in the JDBC client using standard Arrow IPC compression metadata.
  • Keep arrow-compression optional on the Spark engine side. The default none path requires no additional dependency; when zstd is enabled, Kyuubi checks the required Arrow compression capability at runtime and reports a clear error if it is unavailable.
  • Update kyuubi-hive-jdbc-shaded to include/relocate arrow-compression, while excluding zstd-jni and declaring it optional.
  • Exclude commons-compress, since LZ4 is not supported.

For Spark runtimes that do not provide a compatible arrow-compression implementation, users enabling zstd need to add one to the Spark classpath. The default none behavior remains unchanged.

A cluster benchmark with Kyuubi 1.13.0-SNAPSHOT + Spark 3.5.9 showed 78.8%-81.8% fewer Arrow IPC bytes, with fetch time reduced from 19.3s to 7.5s in the 8-column case and from 205.8s to 94.1s in the 34-column case.

How was this patch tested?

Added/updated coverage for:

  • ZSTD compression/decompression and compression-level behavior.
  • Compressed batch slicing across LIMIT boundaries.
  • Full JDBC client <=> Kyuubi server <=> Spark engine ZSTD round trip.
  • The default none path with no arrow-compression on the engine classpath.
  • Runtime capability checking when zstd is enabled without the required dependency.
  • Session-level none -> zstd -> none switching within the same engine.
  • Unsupported LZ4 configuration.

Targeted engine tests and KyuubiOperationPerUserSuite pass on JDK 17 / Spark 3.5.8. The shaded artifacts were also checked to verify the intended arrow-compression / zstd-jni packaging.

Was this patch authored or co-authored using generative AI tooling?

Assisted-by: DeepSeek Harness:deepseek-v4-pro

@github-actions github-actions Bot added kind:infra license, community building, project builds, asf infra related, etc. module:spark module:hive module:ctl kind:build labels Aug 14, 2026
…he engine jar

Spark < 4.1 runtimes do not ship arrow-compression, so the compressed
Arrow result path (and even the default none path when a LIMIT slices a
batch, which always constructs VectorLoader with a decompression factory)
would fail with NoClassDefFoundError unless users added jars manually.
Bundle arrow-compression into the shaded engine jar, relocated under
org.apache.kyuubi.shade.org.apache.arrow.compression, so it is
self-contained on every supported Spark version and cannot conflict with
the arrow-compression jar that Spark 4.1+ ships.

The Arrow vector/memory/format modules and zstd-jni/commons-compress/
commons-io are excluded from shading: every supported Spark runtime
provides them, and excluding them avoids classpath conflicts and native
library relocation issues.
@byronwang123 byronwang123 changed the title [KYUUBI #7635][SPARK] Support Arrow IPC compression for query results (zstd) [KYUUBI #7635][SPARK] Support Zstd compression for Arrow IPC query results Aug 16, 2026
Comment thread externals/kyuubi-spark-sql-engine/pom.xml Outdated
Comment thread externals/kyuubi-spark-sql-engine/pom.xml Outdated
Comment thread pom.xml
Comment thread kyuubi-hive-jdbc/pom.xml
@pan3793

pan3793 commented Aug 17, 2026

Copy link
Copy Markdown
Member

the decision to choose "Arrow IPC compression" looks good to me, Arrow Java has implemented it since 8.0.0, and Spark 3.5 ships Arrow 12.0.1, so that covers all supported Spark versions.

cc @cfmcgrady, could you take a look since you are the author of this feature?

…set#toArrowBatchRdd

The arrow-compression library is now relocated into the engine jar, so the
reflective fallback that invoked the vanilla Spark Dataset#toArrowBatchRdd
is no longer needed; use the plan-based helper directly so the Kyuubi zstd
codec applies. Also reject lz4 explicitly instead of silently falling back
to no compression, and add server-side round-trip coverage.
@pan3793

pan3793 commented Aug 19, 2026

Copy link
Copy Markdown
Member

code change looks almost good to me, and I need to check the packaging result and verify it on a real setup before approval (hope I can find time to finish it in one or two days)

@pan3793

pan3793 commented Aug 19, 2026

Copy link
Copy Markdown
Member

And seems you deleted this part from the PR description? But this is a legally mandated item.

Was this patch authored or co-authored using generative AI tooling?

If generative AI tooling has assisted in authoring or reviewing this patch, please include
an 'Assisted-by: ' trailer that identifies the agent and model.
For example: 'Assisted-by: Claude:claude-opus-4-7' or 'Assisted-by: Claude Opus 4.7'.
If no, write 'No'.
Please refer to the ASF Generative Tooling Guidance for details.

@byronwang123
byronwang123 force-pushed the kyuubi-7635-arrow-ipc-compression branch from 98ed9ec to 34e8ac6 Compare August 19, 2026 09:41
@byronwang123

Copy link
Copy Markdown
Author

code change looks almost good to me, and I need to check the packaging result and verify it on a real setup before approval (hope I can find time to finish it in one or two days)

Thanks for taking another look. I've addressed the remaining naming comment and updated the PR description to reflect the final runtime/packaging behavior, including the generative AI disclosure. Appreciate you checking the packaging and real setup.

@pan3793

pan3793 commented Aug 20, 2026

Copy link
Copy Markdown
Member

CI failure is related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:build kind:infra license, community building, project builds, asf infra related, etc. module:ctl module:hive module:server module:spark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants